(function(){"use strict";BX.namespace("BX.Main.TileGrid");BX.Main.TileGrid.UserOptions=function(t,i,s,e){this.options=null;this.actions=null;this.parent=null;this.url=null;this.init(t,i,s,e)};BX.Main.TileGrid.UserOptions.prototype={init:function(parent,userOptions,userOptionsActions,url){this.url=url;this.parent=parent;try{this.options=eval(userOptions)}catch(t){console.warn("BX.Main.TileGrid.UserOptions.init: Failed parse user options json string")}try{this.actions=eval(userOptionsActions)}catch(t){console.warn("BX.Main.TileGrid.UserOptions.init: Failed parse user options actions json string")}},getCurrentViewName:function(){var t=this.getOptions();return"current_view"in t?t.current_view:null},getViewsList:function(){var t=this.getOptions();return"views"in t?t.views:{}},getCurrentOptions:function(){var t=this.getCurrentViewName();var i=this.getViewsList();var s=null;if(t in i){s=i[t]}if(!BX.type.isPlainObject(s)){s={}}return s},getUrl:function(t){return BX.util.add_url_param(this.url,{GRID_ID:this.parent.getId(),action:t})},getOptions:function(){return this.options||{}},getActions:function(){return this.actions},getAction:function(t){var i=null;try{i=this.getActions()[t]}catch(t){i=null}return i},update:function(t){this.options=t},setColumns:function(t,i){var s=this.getCurrentOptions();if(BX.type.isPlainObject(s)){s.columns=t.join(",");this.save(this.getAction("GRID_SET_COLUMNS"),{columns:s.columns},i)}return this},setColumnsNames:function(t,i){var s={view_id:"default"};if(BX.type.isPlainObject(s)){s.custom_names=t;this.save(this.getAction("SET_CUSTOM_NAMES"),s,i)}return this},setColumnSizes:function(t,i){this.save(this.getAction("GRID_SET_COLUMN_SIZES"),{sizes:t,expand:i})},reset:function(t,i){var s={};if(!!t){s={view_id:"default",set_default_settings:"Y",delete_user_settings:"Y",view_settings:this.getCurrentOptions()}}this.save(this.getAction("GRID_RESET"),s,i)},setSort:function(t,i,s){if(t&&i){this.save(this.getAction("GRID_SET_SORT"),{by:t,order:i},s)}return this},setPageSize:function(t,i){if(BX.type.isNumber(parseInt(t))){this.save(this.getAction("GRID_SET_PAGE_SIZE"),{pageSize:t},i)}},setExpandedRows:function(t,i){BX.type.isArray(t)&&this.save(this.getAction("GRID_SET_EXPANDED_ROWS"),{ids:t},i)},setCollapsedGroups:function(t,i){BX.type.isArray(t)&&this.save(this.getAction("GRID_SET_COLLAPSED_GROUPS"),{ids:t},i)},resetExpandedRows:function(){this.save(this.getAction("GRID_RESET_EXPANDED_ROWS"),{})},saveForAll:function(t){this.save(this.getAction("GRID_SAVE_SETTINGS"),{view_id:"default",set_default_settings:"Y",delete_user_settings:"Y",view_settings:this.getCurrentOptions()},t)},batch:function(t,i){this.save(this.getAction("GRID_SAVE_BATH"),{bath:t},i)},save:function(t,i,s){var e=this;BX.ajax.post(this.getUrl(t),i,function(t){try{t=JSON.parse(t);if(!t.error){e.update(t);if(BX.type.isFunction(s)){s(t)}}}catch(t){}})}}})();